<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'scaleList.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link href="css/mytablecss.css" rel="stylesheet" type="text/css" />
</head>

<body>
	<h3 style="padding:15px;">试卷列表</h3>
	<div class="pd-20">
		<div class="mt-20">
			<table
				class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>
					<tr class="text-c">
						<!-- <th width="80">序号</th> -->
						<th width="50">问卷编号</th>
						<th width="200">问卷名</th>
						<th width="200">导入时间</th>
						<th width="200">问卷类型</th>
						<th width="200">知识点</th>
						<th width="200">创建人</th>
						<th width="200">问卷总分</th>
						<th width="200">问卷形式</th>
						<th width="50">操作</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${requestScope.scaleList}" var="scale">
						<tr>
							<td value="${scale.introduction}"><c:out
									value="${scale.scale_id}"></c:out></td>
							<td value="${scale.guide}"><c:out value="${scale.name}"></c:out></td>
							<td value="${scale.test_time}"><c:out
									value="${scale.import_time}"></c:out></td>
							<td><c:out value="${scale.type}"></c:out></td>
							<td><c:out value="${scale.knowledge}" default="-"></c:out></td>
							<td><c:out value="${scale.manager_name}"></c:out>
								<div style="display:none;">
									<c:out value="${scale.question_info}"></c:out>
								</div></td>
							<td><c:out value="${scale.total_score}"></c:out>
								<div style="display:none;">
									<c:out value="${scale.strategy}"></c:out>
								</div></td>
							<td><c:out value="${scale.form}"></c:out></td>
							<%-- <td style="display:none"><c:out value="${manager.id}"></c:out></td> --%>
							<td class="td-manage"><a title="编辑" class="ml-5 edit"
								style="text-decoration:none" onclick="edit(this)"> <i
									class="Hui-iconfont">&#xe6df;</i></a> <!-- <a title="删除"
								href="javascript:;" onclick="remove(this)" class="ml-5"
								style="text-decoration:none"> <i class="Hui-iconfont">&#xe6e2;</i></a> --></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
	</div>

	<div id="bcg_editor" class="editor_background">
		<form id="scale_editor_form" class="editor_main form form-horizontal">
			<legend>试卷信息窗口 </legend>
			<div>
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">问卷编号:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_scale_id" name="i_scale_id" class="input-text"
							type="text" disabled>
					</div>
				</div>
				<br />
				<div class="row">
					<label class="form-label col-xs-4 col-sm-3">所属类型:</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box span_1"><select id="sel_major"
							class="select" size="1" name="sel_major">
						</select> </span> <span class="select-box span_2" style=""> <select
							id="sel_subject" class="select" size="1" name="sel_subject">

						</select>
						</span> <span class="select-box span_2" style="width: 115px;"> <select
							id="sel_knowledge" class="select" size="1" name="sel_knowledge">
						</select>
						</span>
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">问卷名称:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_scale_name" name="i_scale_name" class="input-text"
							type="text">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">创建人:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_creator" name="i_creator" class="input-text"
							type="text" disabled>
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">问卷类型:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<span class="select-box "><select id="sel_type"
							class="select" size="1" name="sel_type">
								<option value="知识点练习">知识点练习</option>
								<option value="阶段测试">阶段测试</option>
								<option value="论述题自测">论述题自测</option>
								<option value="真题练习">真题练习</option>
								<option value="组卷模考">组卷模考</option>
						</select> </span>
					</div>
				</div>
				<br />

				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">问卷介绍:</label>
					<div class="formControls col-xs-8 col-sm-9 testarea_1">
						<textarea id="ta_introduction" name="ta_introduction"
							class="textarea"></textarea>
					</div>
				</div>
				<br /> <br /> <br /> <br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">问卷指导语:</label>
					<div class="formControls col-xs-8 col-sm-9 testarea_1">
						<textarea id="ta_guide" name="ta_guide" class="textarea"></textarea>
					</div>
				</div>
				<br /> <br /> <br /> <br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">考试时长:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_time" class="input-text " type="time">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">问卷总分 :</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_total_score" name="i_total_score" class="input-text"
							type="text" disabled>
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">导入时间:</label>
					<div
						class="formControls skin-minimal col-xs-8 col-sm-9 input_manager">
						<input id="i_import_time" class="input-text" type="text" disabled>
					</div>
				</div>
				<br /> <br />
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input id="btn_ensure" class="btn btn-primary f-l btn_ensure"
						style="width: 75px;" value="确认" readonly> <input
						id="btn_set_question" class="btn btn-primary btn_ensure1 f-r"
						value="设置题目" readonly> <input id="btn_set_strategy"
						class="btn btn-primary btn_ensure1 f-r hidden" value="设置策略"
						readonly> <input id="btn_exit"
						class="btn btn-primary f-l btn_exit" value="取消" readonly>
				</div>
				<input id="i_scale_form" name="i_scale_form" class="input-text"
					type="text" style="display:none;"> <input
					id="i_question_info" name="i_question_info" class="input-text"
					type="text" style="display:none;">
			</div>
		</form>
	</div>

	<div id="bcg_strategy" class="editor_background">
		<form id="strategy_form" class="editor_main form form-horizontal">
			<legend>策略信息窗口 </legend>
			<div class="row" style="margin-top: 25px;">
				<label class="form-label col-xs-4 col-sm-3">问题总数:</label>
				<div class="formControls col-xs-8 col-sm-9 input_manager">
					<input id="i_question_number" name="i_question_number"
						class="input-text" type="text">
				</div>
			</div>
			<br />
			<div class="row" style="margin-top: 25px;">
				<label class="form-label col-xs-4 col-sm-3">问题难度:</label>
				<div class="formControls col-xs-8 col-sm-9 input_manager"
					style="margin-left: 30px;">
					<span class="select-box span_1"><select id="sel_rank"
						class="select" size="1" name="sel_rank">
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
					</select> </span>
				</div>
			</div>
			<br />

			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input id="btn_ensure2" class="btn btn-primary f-l btn_ensure"
					style="width: 75px;" value="确认" readonly> <input
					id="btn_exit2" class="btn btn-primary f-l btn_exit" value="取消"
					readonly>
			</div>
		</form>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		$('.table-sort').dataTable({
			"aaSorting" : [ [ 0, "asc" ] ],//默认第几个排序
			"bStateSave" : true,//状态保存 
			"bRetrieve" : true,
			"aoColumnDefs" : [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			//{"orderable":false,"aTargets":[7]}// 制定列不参与排序
			]
		});
	});

	//删除按钮
	function remove(widget) {
		//删除数据逻辑
	}

	//编辑按钮
	function edit(widget) {
		var i = 0;
		//还缺：所属类型****
		$(widget).parent("td").siblings("td").each(
				function() {
					switch (i) {
					case 0:
						//问卷编号
						$('#i_scale_id').val($(this).text());
						$('#ta_introduction').val($(this).attr("value"));
						break;
					case 1:
						//问卷名称ta_guide
						$('#ta_guide').val($(this).attr("value"));
						$('#i_scale_name').val($(this).text());
						break;
					case 2:
						//导入时间
						$('#i_time').val($(this).attr("value"));
						$('#i_import_time').val($(this).text());
						break;
					case 3:
						//问卷类型
						$('#sel_type').val($(this).text());
						break;
					case 4:
						//知识点
						$('#sel_knowledge').val($(this).text());
						break;
					case 5:
						//创建人
						$('#i_creator').val($(this).text());
						$("#i_question_info").val(
								$(this).children("div").text());
						/* console.log($("#i_question_info").val()); */
						if ($.trim($("#i_question_info").val()) != "") {
							var questionJson = $
									.parseJSON($("#i_question_info").val());
							sessionStorage.setItem("question_info", $(
									"#i_question_info").val());
						}
						/* console.log(questionJson); */
						break;
					case 6:
						//问卷总分
						$('#i_total_score').val($(this).text());
						var strategy = $(this).children("div").text();
						/* console.log(strategy); */
						if ($.trim(strategy) != "") {
							var strategyJson = $.parseJSON(strategy);
							/* console.log(strategyJson);
							console.log(strategyJson.rank);
							console.log(strategyJson.question_number); */
							$("#sel_rank").val(strategyJson.rank);
							$("#i_question_number").val(
									strategyJson.question_number);
						}

						break;
					case 7:
						//问卷形式
						/* console.log($(this).text()); */
						if ($.trim($(this).text()) == "随机问卷") {
							$("#btn_set_question").addClass('hidden');
							$("#btn_set_strategy").removeClass('hidden');
						} else if ($.trim($(this).text()) == "固定问卷") {
							$("#btn_set_question").removeClass('hidden');
							$("#btn_set_strategy").addClass('hidden');
						}
						$("#i_scale_form").val($(this).text());
						break;
					}
					i++;
				});
		$('#bcg_editor').show();
	}

	//编辑窗口取消按钮
	$(function() {
		$('#btn_exit').on('click', function() {
			$('#bcg_editor').hide();
		});
		$('#btn_exit2').on('click', function() {
			$('#bcg_strategy').hide();
		});
	});
	//编辑窗口确认按钮
	$(function() {
		$('#btn_ensure').on('click', function() {
			//验证表单信息
			if (!$("#scale_editor_form").valid()) {
				return false;
			}
			if (!confirm("确认修改?")) {
				return false;
			}
			//提交修改信息逻辑
			if ($("#i_scale_form").val() == "随机问卷") {
				var strategyInfo = {
					rank : $("#sel_rank").val(),
					question_number : $("#i_question_number").val(),
				};
				var scaleInfo = {
					scale_id : $("#i_scale_id").val(),
					name : $("#i_scale_name").val(),
					introduction : $("#ta_introduction").val(),
					guide : $("#ta_guide").val(),
					test_time : $("#i_time").val(),
					form : $("#i_scale_form").val(),
					strategy : strategyInfo,
				};
			} else {
				var scaleInfo = {
					scale_id : $("#i_scale_id").val(),
					name : $("#i_scale_name").val(),
					introduction : $("#ta_introduction").val(),
					guide : $("#ta_guide").val(),
					test_time : $("#i_time").val(),
					form : $("#i_scale_form").val(),
					question_info : $.trim($(i_question_info).val()),
				};
			}
			/* console.log("scaleList 322");
			console.log($(i_question_info).val()); */
			/* console.log(scaleInfo); */
			/* $.ajax({
			"data" : scaleInfo,
			"url" : "./AlterManagerInfoServlet",
			"type" : "POST",
			"success" : function(result) {
				var resultJson = JSON.parse(result);
				if (resultJson.code == "200") {
					alert("修改成功");
				} else {
					alert("修改失败");
				}
			}
			}); */

		});

		$('#btn_ensure2').on('click', function() {
			//提交策略
			$('#bcg_strategy').hide();
		});
	});

	//编辑窗口设置策略按钮
	$(function() {
		$('#btn_set_strategy').on('click', function() {
			//设置策略信息逻辑
			$("#bcg_strategy").show();
		});
	});

	//编辑窗口设置问题按钮
	$(function() {
		$('#btn_set_question').on('click', function() {
			//设置问题信息逻辑
			localStorage.setItem("scale_id", $("#i_scale_id").val());
			localStorage.setItem("sel_type", $('#sel_type').val());
			location.href = "./manager/insertScale.html";
		});
	});

	//select:change 事件
	$(function() {
		function changeKnowledgeSelect() {
			var subjectInfo = {
				subject : $("#sel_subject").val()
			};
			$.ajax({
				"data" : subjectInfo,
				"url" : "./AlterManagerInfoServlet?method=getKnowledgeSelect",
				"type" : "POST",
				"success" : function(result) {
					var resultJson = JSON.parse(result);
					if (resultJson.code == "200") {
						$("#sel_knowledge").children("option").remove();
						$.each(resultJson.knowledge, function(index, value) {
							/* console.log(value); */
							var text = "<option value="+value+">" + value
									+ "</option>";
							$("#sel_knowledge").append(text);
						});
						/* console.log(resultJson.knowledge); */
					} else {
						console.log("系统出错");
					}
				}
			});
		}

		function changeSubjectSelect() {
			var majorInfo = {
				major : $("#sel_major").val()
			};
			$.ajax({
				"data" : majorInfo,
				"url" : "./AlterManagerInfoServlet?method=getSubjectSelect",
				"type" : "POST",
				"success" : function(result) {
					var resultJson = JSON.parse(result);
					if (resultJson.code == "200") {
						$("#sel_subject").children("option").remove();
						$.each(resultJson.subject, function(index, value) {
							/* console.log(value); */
							var text = "<option value="+value+">" + value
									+ "</option>";
							$("#sel_subject").append(text);
						});
						/* console.log(resultJson.subject); */
						$("#sel_subject").val($("#sel_subject").children("option").eq(0).val());
						$("#sel_subject").trigger("change");
					} else {
						console.log("系统出错");
					}
				}
			});
		}

		$("#sel_major").change(function() {
			changeSubjectSelect();
			changeKnowledgeSelect();
		});

		$("#sel_subject").change(function() {
			changeKnowledgeSelect();
		});
	});

	//设置策略窗口检验
	$("#strategy_form").validate({
		rules : {
			i_question_number : {
				required : true,
				digits : true
			}
		},
		onkeyup : false,
		focusCleanup : true,
		success : "valid"
	});
	//问卷修改窗口检验
	$("#scale_editor_form").validate({
		rules : {
			i_scale_name : {
				required : true,
				maxlength : 500
			},
			ta_introduction : {
				required : true,
				maxlength : 500
			},
			ta_guide : {
				required : true,
				maxlength : 500
			},
			i_total_score : {
				required : true,
				digits : true
			}
		},
		onkeyup : false,
		focusCleanup : true,
		success : "valid"
	});
</script>
</html>
